def pr(z):
    count=0
    if z%2==0:
        return False
    else:
        for i in range(2,z):
            if z%i==0:
                count+=1
        if count==0:return True
        else: return False
digital=['zero','one','two','three','four','five','six','seven','eight','nine']
s=input().split()
if len(s)==3:
    if s[0] in digital and s[0]!='zero':
        a=digital.index(s[0])
        b=digital.index(s[1])
        c=digital.index(s[2])
        x=a*100+b*10+c
        for y in range (x,1,-1):
            if pr(y):
                q=y
                break
        for v in range(x,1010):
            if pr (v):
                w=v
                break
        if (x-q)<=(w-y):
            print(q)
        else:
            print(w)
    else:
        print('wrong input')
else:
        print('wrong input')
